package com.example.basic.receiver;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.util.Log;

import com.example.basic.base.BaseReceiver;
import com.example.basic.utils.NetworkUtils;


public class NetworkReceiver extends BaseReceiver {
    private static final String TAG = "NetworkReceiver";

    private Context context;

    public NetworkReceiver() {
    }

    @Override
    public void register(Context context) {
        this.context = context;
        super.registerSelfNoData(context, ConnectivityManager.CONNECTIVITY_ACTION);
    }

    @Override
    protected void onAction(Intent intent) {
        //使用其他方式判断
        switch (NetworkUtils.getConnectState(context)) {
            case MOBILE:
                Log.e(TAG, "当前连接了移动数据");
                break;
            case WIFI:
                Log.e(TAG, "当前连接了Wifi");
                break;
            case UN_CONNECTED:
                Log.e(TAG, "当前没有网络连接");
                break;
        }
    }
}
